package com.xyzh05.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

@Entity
@Table(name="comment")
@Searchable
@XmlRootElement
public class Comment extends BaseObject implements Serializable {
    private Long id;
    private Notepad notepad;
    private Comment comment;
    private Long userId;
    private Date replyTime;
    private String content;
    private Short mode;
    private Short level;
    private Short status;
    private Set<Comment> comments = new HashSet<Comment>(0);

    @Id @GeneratedValue(strategy=GenerationType.AUTO) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="notepad_id", nullable=false)
    public Notepad getNotepad() {
        return this.notepad;
    }
    
    public void setNotepad(Notepad notepad) {
        this.notepad = notepad;
    }
    
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="parent_id")
    public Comment getComment() {
        return this.comment;
    }
    
    public void setComment(Comment comment) {
        this.comment = comment;
    }
    
    @Column(name="user_id", nullable=false)
    @SearchableProperty
    public Long getUserId() {
        return this.userId;
    }
    
    public void setUserId(Long userId) {
        this.userId = userId;
    }
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="reply_time", nullable=false, length=19)
    @SearchableProperty
    public Date getReplyTime() {
        return this.replyTime;
    }
    
    public void setReplyTime(Date replyTime) {
        this.replyTime = replyTime;
    }
    
    @Column(name="content", nullable=false, length=512)
    @SearchableProperty
    public String getContent() {
        return this.content;
    }
    
    public void setContent(String content) {
        this.content = content;
    }
    
    @Column(name="mode", nullable=false)
    @SearchableProperty
    public Short getMode() {
        return this.mode;
    }
    
    public void setMode(Short mode) {
        this.mode = mode;
    }
    
    @Column(name="level", nullable=false)
    @SearchableProperty
    public Short getLevel() {
        return this.level;
    }
    
    public void setLevel(Short level) {
        this.level = level;
    }
    
    @Column(name="status", nullable=false)
    @SearchableProperty
    public Short getStatus() {
        return this.status;
    }
    
    public void setStatus(Short status) {
        this.status = status;
    }
    
    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="comment")
    public Set<Comment> getComments() {
        return this.comments;
    }
    
    public void setComments(Set<Comment> comments) {
        this.comments = comments;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Comment pojo = (Comment) o;

        if (notepad != null ? !notepad.equals(pojo.notepad) : pojo.notepad != null) return false;
        if (comment != null ? !comment.equals(pojo.comment) : pojo.comment != null) return false;
        if (userId != null ? !userId.equals(pojo.userId) : pojo.userId != null) return false;
        if (replyTime != null ? !replyTime.equals(pojo.replyTime) : pojo.replyTime != null) return false;
        if (content != null ? !content.equals(pojo.content) : pojo.content != null) return false;
        if (mode != null ? !mode.equals(pojo.mode) : pojo.mode != null) return false;
        if (level != null ? !level.equals(pojo.level) : pojo.level != null) return false;
        if (status != null ? !status.equals(pojo.status) : pojo.status != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (notepad != null ? notepad.hashCode() : 0);
        result = 31 * result + (comment != null ? comment.hashCode() : 0);
        result = 31 * result + (userId != null ? userId.hashCode() : 0);
        result = 31 * result + (replyTime != null ? replyTime.hashCode() : 0);
        result = 31 * result + (content != null ? content.hashCode() : 0);
        result = 31 * result + (mode != null ? mode.hashCode() : 0);
        result = 31 * result + (level != null ? level.hashCode() : 0);
        result = 31 * result + (status != null ? status.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("notepad").append("='").append(getNotepad()).append("', ");
        sb.append("comment").append("='").append(getComment()).append("', ");
        sb.append("userId").append("='").append(getUserId()).append("', ");
        sb.append("replyTime").append("='").append(getReplyTime()).append("', ");
        sb.append("content").append("='").append(getContent()).append("', ");
        sb.append("mode").append("='").append(getMode()).append("', ");
        sb.append("level").append("='").append(getLevel()).append("', ");
        sb.append("status").append("='").append(getStatus()).append("', ");
        
        sb.append("]");
      
        return sb.toString();
    }

}
